These samples demonstrate how to sort results using "orderby" in LINQ to XML.

[Category("Sort")]
[Description("Sort customers by name in ascending order")]
public void XLinq56()
{
XDocument doc = XDocument.Load("nw_customers.xml");
var query =
from
customer in doc.Descendants("Customers")
orderby
(string)customer.Elements("ContactName").First()
select
customer.Element("ContactName");
XElement result =
new XElement("SortedCustomers", query);
Console.WriteLine(result);
}
[Category("Sort")] [Description("Sort customers by name in ascending order")] public void XLinq56() { XDocument doc = XDocument.Load("nw_customers.xml"); var query = from customer in doc.Descendants("Customers") orderby (string)customer.Elements("ContactName").First() select customer.Element("ContactName"); XElement result = new XElement("SortedCustomers", query); Console.WriteLine(result); }
For more information on LINQ to XML: http://msdn.microsoft.com/en-us/library/bb387098.aspx